<?php 
include("db/connect.php");
include("prename.php");
if(@$_POST["type"]==1){
	$sqldeletecustomer="delete from customer where cus_id='".@$_POST["temp"]."'";
	$querydelete=mysql_query($sqldeletecustomer);
	}
	else if(@$_POST["type"]==3){
		$sqlupdate="update customer set cus_title='".@$_POST["cus_title"]."',cus_name='".@$_POST["cus_name"]."',cus_lastname='".@$_POST["cus_lastname"]."',cus_addr='".@$_POST["cus_addr"]."',province_id='".@$_POST["province_id"]."',amphur_id='".@$_POST["amphur_id"]."',tambol_id='".@$_POST["tambol_id"]."',cus_postal='".@$_POST["cus_postal"]."',cus_tel='".@$_POST["cus_tel"]."',cus_mail='".@$_POST["cus_mail"]."' where cus_id='".@$_POST["temp"]."'";
		$queryupdatecustomer=mysql_query($sqlupdate);
		}
		$sqlselectcustomer="select * from customer,province,amphur,tambol";
		$sqlselectcustomer.=" where customer.province_id=province.province_id and";
		$sqlselectcustomer.=" customer.amphur_id=amphur.amphur_id and";
		$sqlselectcustomer.=" customer.tambol_id=tambol.tambol_id";
		$sqlselectcustomer.=" group by cus_id";
		$queryselectcustomer=mysql_query($sqlselectcustomer);
?>
<table width="100%" height="132" border="1" id="tbmanage">
<thead>
 <tr>
  	<th width="21%">ชื่อ-นามสกุล</th>
    <th width="32%">ที่อยู่</th>
    <th width="13%">รหัสไปรษณีย์</th>
    <th width="12%">เบอร์โทรศัพท์</th>
    <th width="5%">Email</th>
    <th width="5%">แก้ไข</th>
    <th width="5%">ลบ</th>
    <th width="7%">สั่งซื้อสินค้า</th>
  </tr>
</thead>
<tbody style="color:black !important;">
  <?php 
  while($resultcustomer=@mysql_fetch_array($queryselectcustomer)){
  ?>
   <tr>
  	<td><?php echo (prename($resultcustomer["cus_title"])." ".$resultcustomer["cus_name"])." ".$resultcustomer["cus_lastname"]?></td>
    <td><?php echo $resultcustomer["cus_addr"]." ต.".$resultcustomer["tambol_name"]." อ.".$resultcustomer["amphur_name"]." จ.".$resultcustomer["province_name"]?></td>
    <td><?php echo $resultcustomer["cus_postal"]?></td>

    <td><?php echo  $resultcustomer["cus_tel"]?></td>
    <td><?php echo $resultcustomer["cus_mail"]?></td>
    <td><a href="Javascript:ajaxmanage(2,<?php echo $resultcustomer["cus_id"];?>);">แก้ไข</a></td>
    <td><a href="Javascript:ajaxmanage(1,<?php echo $resultcustomer["cus_id"];?>);" onclick="return window.confirm('ต้องการลบใช่ไหม')">ลบ</a></td>
    <td><a href="Javascript:ajaxmanage(5,<?php echo $resultcustomer["cus_id"];?>);">สั่งซื้อสินค้า</a></td>
  </tr>
  <?php }?>
    </tbody>
</table>
<script>
 $(function() {
		/* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
		/* For cell text alignment */
		$("table td:first-child, table th:first-child").addClass("first");
		/* For removing the last border */
		$("table td:last-child, table th:last-child").addClass("last");
});</script>
<script>
$(document).ready(function(){

  	var oTable = $('#tbmanage').dataTable({
          "bJQueryUI": true,
          "sPaginationType": "full_numbers"
      });
});
	  
	
</script>